<%@include file="/WEB-INF/templates/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>


<h2>${pageTitle}</h2>

<c:choose>
    <c:when test="${aantalForums != 0 || aantalThreads != 0}">
        <!-- Wanneer er forums opgeslagen zijn, worden ze hier getoond -->
        <table class="zebra">
            <tr>
                <th>
                    <strong>Forum topics</strong>
                </th>
                <th>
                    <strong>Description</strong>
                </th>
                <th>
                    <strong>Author</strong>
                </th>
                <th>

                </th>
            </tr>
            <c:forEach var="tempForum" items="${forumsUitSessie}">
                <!-- Forum topics --------------------------------------------------->
                <c:choose>
                    <c:when test="${tempForum.forumtopic_isdeleted == 0}">
                        <tr>
                            <td width="120px;">
                                <a href="${url}forum/topic_view?topic_id=${tempForum.forumtopicid}">${tempForum.forumTopicName}</a>
                            </td>
                            <td>
                                <c:set var="body" value="${tempForum.forumtopicbody}"/>
                                <c:choose>
                                    <c:when test="${fn:length(body) > 100}">
                                    ${fn:substring(body, 0, 100)}...                                     
                                    </c:when>
                                    <c:otherwise>
                                        ${tempForum.forumtopicbody}
                                        
                                    </c:otherwise>
                                </c:choose>
                            </td>
                            <td>
                                ${tempForum.user.userName}
                            </td>
                            <td>
                                <a class="icon view" href="${url}forum/topic_view?topic_id=${tempForum.forumtopicid}">${tempForum.forumTopicName}</a>
                                <c:choose>
                                    <c:when test="${tempForum.user.userId == currentUserId}">
                                        <a class="icon delete" title="Delete topic" href="${url}forum/delete_topic?topic_id=${tempForum.forumtopicid}"></a>

                                    </c:when>
                                    <c:when test="${currentUserType == 3}">
                                        <a class="icon delete" title="Admin delete topic" href="${url}forum/admin_delete_topic?topic_id=${tempForum.forumtopicid}"></a>
                                    </c:when>

                                </c:choose>


                            </td>
                        </tr>
                    </c:when>

                </c:choose>
            </c:forEach>

            <tr height="10px;"></tr>
        </table>
        <table class="zebra">

            <!-- Forum threads ----------------------------------------------------->
            <tr>
                <th>
                    <strong>Forum threads</strong>
                </th>
                <th>
                    <strong>Description</strong>
                </th>
                <th>
                    <strong>Author</strong>
                </th>
                <th>
                    <strong> </strong>
                </th>
            </tr>
            <c:forEach var="tempThread" items="${threadsUitSessie}">
                <c:choose>
                    <c:when test="${tempThread.forumthread_isdeleted == 0}">

                        <tr>
                            <td width="120px;">
                                <a href="${url}forum/thread_view?thread_id=${tempThread.forumThreadId}">${tempThread.forumThreadName}</a>
                            </td>
                            <td>
                                ${tempThread.forumThreadBody}
                            </td>
                            <td>
                                ${tempThread.user.userName}
                            </td>
                            <td>
                                <a class="icon view" href="${url}forum/thread_view?thread_id=${tempThread.forumThreadId}">${tempThread.forumThreadName}</a>
                                <c:choose>
                                    <c:when test="${tempThread.user.userId == currentUserId}">
                                        <a class="icon delete" title="Delete thread" href="${url}forum/delete_thread?thread_id=${tempThread.forumThreadId}"></a>

                                    </c:when>
                                    <c:when test="${currentUserType == 3}">
                                        <a class="icon delete" title="Admin delete thread" href="${url}forum/admin_delete_thread?thread_id=${tempThread.forumThreadId}"></a>
                                    </c:when>

                                </c:choose>
                            
                            </td>
                        </tr>
                    </c:when>

                </c:choose>
            </c:forEach>
        </table>
    </c:when>
    <c:otherwise>
        <!-- Als er geen gebruikers zijn, wordt deze melding getoond -->
        There are no forums or threads found.
    </c:otherwise>
</c:choose>

</br>
<p>
    <a class="button" href="${url}forum/topic_add">Start new topic</a>
</p>
<p>
    <a class="button" href="${url}forum/thread_add">Start new thread</a>
</p>
<p>
    <a class="button" href="${url}index">Go back to the index</a>
</p>